package com.vtuzx.kingdee.xqc_core.dao;

import com.vtuzx.core.db.mongo.impl.VtuzxDaoImpl;
import com.vtuzx.kingdee.xqc_core.bean.VtuzxArrayList;
import org.bson.Document;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 对接系统接口履历Dao
 */
@Component
public class PrdInDetailBoxDao extends VtuzxDaoImpl {
    /** 集合名称 */
    public static final String NAME = "t_prd_in_detail_box";

    public PrdInDetailBoxDao() {
        super(NAME);
    }

    /**
     * 用于成品入库根据车间收货单号分组查询出箱数和总重
     * @param cond
     * @return
     */
    public Iterator<Document> findSumCount(Criteria cond,List<String> prdColBillNoList) {
        List<Document> docList = new ArrayList<>();
        docList.add(new Document("$match",new Document("prdColBillNo",new Document("$in",prdColBillNoList))));
        docList.add(new Document("$group", new Document("_id", "$prdColBillNo").append("sumCount", new Document("$sum", "$count")).append("sumBoxCount",new Document("$sum",1))));
        System.out.println(this.aggregate(docList));
        return this.aggregate(docList);
    }

    public Iterator<Document> findTest(Criteria cond,List<String> prdColBillNoList) {
        List<Document> docList = new ArrayList<>();
        docList.add(new Document("$match",new Document("prdColBillNo",new Document("$in",prdColBillNoList))));
        docList.add(new Document("$project", new Document("_id", 0).append("materialName", 1).append("materialNo",1)));
        System.out.println(this.aggregate(docList));
        return this.aggregate(docList);
    }

}